import type { PageParam, PageResult } from '@vben/request';

import { requestClient } from '#/api/request';

export namespace InfraConfigApi {
  /** 参数配置信息 */
  export interface Config {
    id?: number | undefined;
    category?: string;
    name?: string;
    key?: string;
    value?: string;
    type?: number;
    visible?: boolean;
    remark?: string | undefined;
    createTime?: Date;
  }
}

/** 查询参数列表 忽略租户 */
export function listIgnoreTenant(params: PageParam) {
  return requestClient.get<Array<InfraConfigApi.Config>>(
    '/infra/config/listIgnoreTenant',
    {
      params,
    },
  );
}
/** 查询参数列表*/
export function list(params: PageParam) {
  return requestClient.get<Array<InfraConfigApi.Config>>('/infra/config/list', {
    params,
  });
}
/** 查询参数列表 */
export function getConfigPage(params: PageParam) {
  return requestClient.get<PageResult<InfraConfigApi.Config>>(
    '/infra/config/page',
    {
      params,
    },
  );
}
/** 查询参数列表 忽略租户 */
export function getConfigPageIgnoreTenant(params: PageParam) {
  return requestClient.get<PageResult<InfraConfigApi.Config>>(
    '/infra/config/pageIgnoreTenant',
    {
      params,
    },
  );
}
/** 查询参数详情 */
export function getConfig(id: number) {
  return requestClient.get<InfraConfigApi.Config>(`/infra/config/get?id=${id}`);
}

/** 根据参数键名查询参数值 */
export function getConfigKey(configKey: string) {
  return requestClient.get<string>(
    `/infra/config/get-value-by-key?key=${configKey}`,
  );
}

/** 新增参数 */
export function createConfig(data: InfraConfigApi.Config) {
  return requestClient.post('/infra/config/create', data);
}
/** 新增参数 忽略租户 */
export function createConfigIgnoreTenant(data: InfraConfigApi.Config) {
  return requestClient.post('/infra/config/create-ignore-tenant', data);
}
/** 修改参数 */
export function updateConfig(data: InfraConfigApi.Config) {
  return requestClient.put('/infra/config/update', data);
}
/** 修改参数 忽略租户*/
export function updateConfigIgnoreTenant(data: InfraConfigApi.Config) {
  return requestClient.put('/infra/config/update-ignore-tenant', data);
}
/** 批量修改参数 忽略租户*/
export function updateBatchIgnoreTenant(data: InfraConfigApi.Config[]) {
  return requestClient.put('/infra/config/updateBatchIgnoreTenant', data);
}
/** 批量修改参数 忽略租户*/
export function updateBatch(data: InfraConfigApi.Config[]) {
  return requestClient.put('/infra/config/updateBatch', data);
}
/** 删除参数 */
export function deleteConfig(id: number) {
  return requestClient.delete(`/infra/config/delete?id=${id}`);
}
/** 删除参数 忽略租户*/
export function deleteConfigIgnoreTenant(id: number) {
  return requestClient.delete(`/infra/config/delete-ignore-tenant?id=${id}`);
}
/** 批量删除参数 */
export function deleteConfigList(ids: number[]) {
  return requestClient.delete(`/infra/config/delete-list?ids=${ids.join(',')}`);
}
/** 批量删除参数 忽略租户*/
export function deleteConfigListIgnoreTenant(ids: number[]) {
  return requestClient.delete(
    `/infra/config/delete-list-ignore-tenant?ids=${ids.join(',')}`,
  );
}

/** 导出参数 */
export function exportConfig(params: any) {
  return requestClient.download('/infra/config/export-excel', {
    params,
  });
}
/** 导出参数 忽略租户 */
export function exportConfigIgnoreTenant(params: any) {
  return requestClient.download('/infra/config/export-excel-ignore-tenant', {
    params,
  });
}
